#include <bits/stdc++.h>

void printArr(int *arr, int length)
{
    for (int pointer = 0; pointer < length; pointer++)
    {
        std::cout << *(arr + pointer) << ' ';
    }
    std::cout << std::endl;
}

void bubbleSort(int *arr, int length)
{
    for (int pointerA = 0; pointerA < length - 1; pointerA++)
    {
        for (int pointerB = 0; pointerB < length - 1 - pointerA; pointerB++)
        {
            if (*(arr + pointerB) > *(arr + pointerB + 1))
            {
                int tempValue = *(arr + pointerB);
                *(arr + pointerB) = *(arr + pointerB + 1);
                *(arr + pointerB + 1) = tempValue;
            }
        }
    }
}

void selectSort(int *arr, int length)
{
    for (int pointerA = 0; pointerA < length; pointerA++)
    {
        int minValue = *(arr + pointerA);
        int minValuePosition = pointerA;
        for (int pointerB = pointerA + 1; pointerB < length; pointerB++)
        {
            if (*(arr + pointerB) < minValue)
            {
                minValue = *(arr + pointerB);
                minValuePosition = pointerB;
            }
        }
        int tempValue = *(arr + pointerA);
        *(arr + pointerA) = minValue;
        *(arr + minValuePosition) = tempValue;
    }
}

void insertSort(int *arr, int length)
{
    for (int pointerA = 1; pointerA < length; pointerA++)
    {
        int insertedValue = *(arr + pointerA);
        int pointerB = pointerA - 1;
        while (pointerB >= 0 && *(arr + pointerB) > insertedValue)
        {
            *(arr + pointerB + 1) = *(arr + pointerB);
            pointerB--;
        }
        *(arr + pointerB + 1) = insertedValue;
    }
}

int main()
{
    int arr[5] = {5, 4, 3, 2, 1};
    printArr(arr, 5);
    insertSort(arr, 5);
    printArr(arr, 5);
}